
function contains (
  node,
  target,
  childrenKey = 'children',
  compareFn = (x, y) => x === y,
  deep = true
) {
  const walk = function (parent) {
    const children = parent[childrenKey] || []
    let result = false
    for (let i = 0, j = children.length; i < j; i++) {
      const child = children[i]
      if (compareFn(child, target) || (deep && walk(child))) {
        result = true
        break
      }
    }
    return result
  }

  return walk(node)
}

export default {
  contains
}
